﻿#include "slideshowdialog.h"
#include "ui_slideshowdialog.h"
#include "prelistwid.h"
#include "protreewidget.h"

SlideShowDialog::SlideShowDialog(QWidget *parent, QTreeWidgetItem *first_item, QTreeWidgetItem *last_item)
    : QDialog(parent),_first_item(first_item),_last_item(last_item),
    ui(new Ui::SlideShowDialog)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
    ui->slidPreBtn->SetIcons(":/icon/previous.png",":/icon/previous_hover.png",":/icon/previous_press.png");
    ui->slidNextBtn->SetIcons(":/icon/next.png",":/icon/next_hover.png",":/icon/next_press.png");
    ui->closeBtn->SetIcons(":/icon/closeshow.png",":/icon/closeshow_hover.png",":/icon/closeshow_press.png");
    ui->playBtn->SetIcons(":/icon/play.png",":/icon/play_hover.png",":/icon/play_press.png",
                          ":/icon/pause.png",":/icon/pause_hover.png",":/icon/pause_press.png");

    //关闭窗口
    connect(ui->closeBtn,&QPushButton::clicked,this,&SlideShowDialog::close);
    connect(ui->slidNextBtn,&QPushButton::clicked,this,&SlideShowDialog::SlotSlideNext);
    connect(ui->slidPreBtn,&QPushButton::clicked,this,&SlideShowDialog::SlotSlidePre);


    auto *prelistWid = dynamic_cast<PreListWid*>(ui->preListWidget);

    //连接了PicAnimationWid的SigUpPreList信号，可以实现上面动画播放时将图像的预览图添加到列表中的效果。
    connect(ui->picAnimation,&PicAnimationWid::SigUpPreList,prelistWid,&PreListWid::SlotUpPreList);

    //连接了PicAnimationWid的SigSelectItem信号，可以实现上面动画播放时根据图像显示预览图选中效果。
    connect(ui->picAnimation,&PicAnimationWid::SigSelectItem,prelistWid,&PreListWid::SlotUpSelect);

    //连接了PreListWid的SigUpSelectShow信号，可以实现点击下方预览图，上方显示对应的动画效果。
    connect(prelistWid,&PreListWid::SigUpSelectShow,ui->picAnimation,&PicAnimationWid::SlotUpSelectShow);

    connect(ui->playBtn,&PicStateBtn::clicked,ui->picAnimation,&PicAnimationWid::SlotStartOrStop);

    connect(ui->picAnimation,&PicAnimationWid::SigStart,ui->playBtn,&PicStateBtn::SlotStart);
    connect(ui->picAnimation,&PicAnimationWid::SigStop,ui->playBtn,&PicStateBtn::SlotStop);

    //开始和暂停音乐
    auto * protree_widget = dynamic_cast<ProTreeWidget*>(parent);
    connect(ui->picAnimation,&PicAnimationWid::SigStartMusic,protree_widget,&ProTreeWidget::SlotStartMusic);
    connect(ui->picAnimation,&PicAnimationWid::SigStopMusic,protree_widget,&ProTreeWidget::SlotStopMusic);

    ui->picAnimation->SetPixmap(_first_item);
    ui->picAnimation->Start();
}

SlideShowDialog::~SlideShowDialog()
{
    delete ui;
}

void SlideShowDialog::SlotSlideNext()
{
    ui->picAnimation->SlideNext();
}

void SlideShowDialog::SlotSlidePre()
{
    ui->picAnimation->SlidePre();
}
